home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Essential Home & Business Collection
/
The Essential Home & Business Collection.iso
/
27
/
3
/
5
/
HP22D5.ZIP
/
EXTERN
/
FF.C
< prev
next >
Wrap
Text File
|
1991-04-16
|
3KB
|
168 lines
#include <dos.h>
#include <stdio.h>
#include <stdarg.h>
#include "extern.h"
#include "keycodes.h"
extern PTR far GetDTA();
extern far GetFirst(STRING); /* Mask */
extern far GetNext();
PTR near dta;
char near searchspec[80];
char near filespec[80];
char near spec[80];
int near rc;
PTR near t;
HANDLE near hmsg;
BOOLEAN near aborted;
int pascal near CheckEscape()
{
MSG Msg;
do {
GetEvent(&Msg);
if ((Msg.Event == EVENT_KEYPRESS) && (Msg.KeyWord == kb_ESCAPE)) {
return(TRUE);
}
} while (Msg.Event != EVENT_IDLE);
return(FALSE);
}
pascal near add()
{
HANDLE hdl;
int slen;
slen = strlen(searchspec) - 3;
strncpy(spec,searchspec,slen);
sprintf(spec+slen,"%s",dta + 30);
hdl = stoh(spec);
SendPageMsg(hmsg,1,hdl);
FreeHandle(hdl);
}
int pascal near find()
{
HANDLE hDirs = NULL;
int sz,oldsz;
PTR p;
if (CheckEscape()) goto abort;
strcpy(spec,searchspec);
strcpy(spec + strlen(spec) - 3,filespec);
rc = GetFirst(spec);
while (!rc) {
if (!(*(BYTE *)(dta + 21) & 0x10)) {
add();
}
rc = GetNext();
}
sz = 0;
rc = GetFirst(searchspec);
while (!rc) {
if (*(BYTE *)(dta + 21) & 0x10) {
if (*(dta + 30) != '.') {
oldsz = sz;
sz += strlen(dta + 30) + 1;
if (oldsz) ReAllocHandle(hDirs,sz);
else hDirs = NewHandle(sz);
strcpy(deref(hDirs) + oldsz,dta + 30);
}
}
rc = GetNext();
}
if (CheckEscape()) goto abort;
p = searchspec + strlen(searchspec) - 3;
oldsz = 0;
while (oldsz < sz) {
t = deref(hDirs) + oldsz;
strcpy(p,t);
strcat(p,"\\*.*");
oldsz += strlen(t) + 1;
if (find()) {
abort:
aborted = TRUE;
sz = 1;
goto end;
}
*(p + strlen(p) - 4) = '\0';
}
sz = 0;
end:
FreeHandle(hDirs);
return(sz);
}
/*
** FINDFILE
**
** This routine locates a file anywhere on a disk drive. Each file that is
** found is sent as a parameter to a handler called "foundFile" so that
** the pad can process it any way it finds necessary.
**
** Returns:
**
** FALSE normal return value
** TRUE the user aborted
**
** Example:
**
** get findFile("C","MYFILE.*");
**
** get findFile(char 1 of the directory,"MYFILE*.*");
** if it the answer "You aborted!" with "Ok";
*/
FindFile(int NumArgs,HANDLE hDrive,HANDLE hFileSpec)
{
if (NumArgs != 2) return(STOP);
sprintf(searchspec,"%c:\\*.*",*deref(hDrive));
strcpy(filespec,deref(hFileSpec));
dta = GetDTA();
hmsg = stoh("foundFile");
aborted = FALSE;
find();
FreeHandle(hmsg);
ReturnValue(btoh(aborted));
return(STOP);
}
POOL pascal Pool[] = {
{ "findFile", /* name of the handler */
FindFile, /* pointer to the handler */
0, /* reserved */
FUNCTION}, /* this is a handler, not a function */
{ NULL, /* NULLs signify the end of the table */
NULL,
0,
0} };